package cn.edu.nsmc.modules.sys.service.impl;

import cn.edu.nsmc.common.utils.R;
import cn.edu.nsmc.modules.sys.dao.SysHomepagePushDao;
import cn.edu.nsmc.modules.sys.entity.SysHomepagePush;
import cn.edu.nsmc.modules.sys.service.SysHomepagePushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysHomepagePushServiceImpl implements SysHomepagePushService {
    @Autowired
    private SysHomepagePushDao sysHomepagePushMapper;

    @Override
    public SysHomepagePush getById(Long id) {
        return sysHomepagePushMapper.getById(id);
    }

    @Override
    public R getAll(String title,Integer page,Integer size) {
        Map<String,Object> data = new HashMap<String,Object>();
        data.put("list",sysHomepagePushMapper.getAll(title,page,size));
        data.put("total",sysHomepagePushMapper.count(title));
        return R.success("查询数据成功",data);
    }

    @Override
    public R insert(SysHomepagePush sysHomepagePush) {
        Date date = new Date(System.currentTimeMillis());
        sysHomepagePush.setCreateTime(date);
        sysHomepagePush.setUpdateTime(date);
        sysHomepagePushMapper.insert(sysHomepagePush);
        return R.ok("新增数据成功");
    }

    @Override
    public R update(SysHomepagePush sysHomepagePush) {
        sysHomepagePush.setUpdateTime(new Date(System.currentTimeMillis()));
        sysHomepagePushMapper.update(sysHomepagePush);
        return R.ok("修改数据成功");
    }

    @Override
    public R delete(Long id) {
        sysHomepagePushMapper.delete(id);
        return R.ok("删除数据成功");
    }
}
